package com.jiashihui.schema_lgorithm.spring.aspect.proxy;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author jiashihui
 * @describe: 环绕通知的实现类
 * @date 2019/03/25
 */
public class TestMethodInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {

        System.out.println("执行环绕通知--->" + "正在执行的方法名为" + invocation.getMethod().getName());

        Object[] arguments = invocation.getArguments();
        int a = (int) arguments[0];
        int b = (int) arguments[1];
        if (b == 0) {
            System.err.println("除数不能为0");
            return -1;
        }
        if (a == 0) {
            return 0;
        }
        return invocation.proceed();
    }
}
